﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using BEGDC.PreContract.BLL;
using System.Text;

namespace PreContractWeb.Report
{
    public partial class SaveExcelReport : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            string rptType = "";
            string rptDate = "";
            DataTable dtTable;

            if (Request.QueryString["rptType"] != null && Request.QueryString["rptDate"]!=null)
            {
                rptType = Request.QueryString["rptType"];

                if (rptType.Contains("Q"))
                    this.RptType.Value = "Quarterly";
                else
                    this.RptType.Value = "Monthly";

                rptDate = Request.QueryString["rptDate"];
                //Session[rptType] = null;
                if (Session[rptType] == null)
                    this.msg.Value="TimeOut";
                else
                {
                    //byte[] bytes = Encoding.ASCII.GetBytes(Session[rptType].ToString());
                    //dtTable = ReportHelper.SaveHistoryReport(rptDate, rptType, System.Text.Encoding.UTF8.GetString(bytes));
                    dtTable = ReportHelper.SaveHistoryReport(rptDate, rptType, Session[rptType].ToString());

                    if (dtTable == null)
                        this.msg.Value = "Error occured!";
                    else
                    {
                        this.msg.Value = "";
                        this.RptID.Value = dtTable.Rows[0][0].ToString();
                        this.RptDate.Value = System.Convert.ToDateTime(dtTable.Rows[0][1].ToString()).ToString("yyyy-MM-dd");
                       
                    }
                }
            }
            else
            {
                this.msg.Value="TimeOut";
            }
        }
    }
}
